﻿Imports System
Imports System.CodeDom
Imports System.Collections.Generic
Imports System.Collections.Specialized
Imports System.ComponentModel.Design.Serialization
Imports System.Workflow.ComponentModel

Namespace System.Workflow.ComponentModel.Serialization
    Friend NotInheritable Class SynchronizationHandlesCodeDomSerializer
        Inherits CodeDomSerializer
        ' Methods
        Public Overrides Function Serialize(ByVal manager As IDesignerSerializationManager, ByVal obj As Object) As Object
            If (manager Is Nothing) Then
                Throw New ArgumentNullException("manager")
            End If
            If (obj Is Nothing) Then
                Throw New ArgumentNullException("obj")
            End If
            Dim expression As CodeExpression = Nothing
            Dim statements As CodeStatementCollection = [TryCast](manager.Context.Item(GetType(CodeStatementCollection)),CodeStatementCollection)
            If (statements Is Nothing) Then
                Return expression
            End If
            Dim activity As Activity = DirectCast(manager.Context.Item(GetType(Activity)), Activity)
            MyBase.SerializeToExpression(manager, activity)
            Dim is2 As ICollection([Of] String) = [TryCast](obj,ICollection([Of] String))
            If (is2 Is Nothing) Then
                Throw New ArgumentException(SR.GetString("Error_UnexpectedArgumentType", New Object() { GetType(StringCollection).FullName }), "obj")
            End If
            Dim uniqueName As String = MyBase.GetUniqueName(manager, New StringCollection)
            statements.Add(New CodeVariableDeclarationStatement(obj.GetType, uniqueName, New CodeObjectCreateExpression(obj.GetType, New CodeExpression(0  - 1) {})))
            Dim str2 As String
            For Each str2 In is2
                statements.Add(New CodeMethodInvokeExpression(New CodeMethodReferenceExpression(New CodeVariableReferenceExpression(uniqueName), "Add"), New CodeExpression() { New CodePrimitiveExpression(str2) }))
            Next
            Return New CodeVariableReferenceExpression(uniqueName)
        End Function

    End Class
End Namespace

